<template>
  <div class="user">
    <div class="user_top">
      <svg class="icon" aria-hidden="true" @click="router.push('/')">
        <use xlink:href="#icon-zuojiantou"></use>
      </svg>
      <svg class="icon iconLeft" aria-hidden="true" @click="router.push('/search')">
        <use xlink:href="#icon-sousuo"></use>
      </svg>
    </div>
    <div class="user_center">
      <div class="center_top">
        <div class="img_div">
          <img v-if="token" :src="profile.avatarUrl" alt="" class="center_top_img" />
          <img v-else src="" alt="" class="center_top_img" />
        </div>
        <div v-if="token" class="center_top_div_login">
          <div class="center_top_div_name">
            <span class="span">{{ profile.nickname }}</span>
            <!-- 会员用户图标 -->
            <svg
              class="icon icon_span"
              aria-hidden="true"
              @click="router.back()"
              v-if="profile.vipType"
            >
              <use xlink:href="#icon-VIPyonghu"></use>
            </svg>
            <!-- 普通用户图标 -->
            <svg class="icon icon_span" aria-hidden="true" @click="router.back()" v-else>
              <use xlink:href="#icon-putongyonghu"></use>
            </svg>
          </div>
          <!-- 关注， 粉丝 ， 等级 -->
          <div class="center_top_div_info">
            <span>{{ profile.follows }}关注</span>
            <span>{{ profile.followeds }}粉丝</span>
            <span>Lv.{{ userInfo.level }}</span>
          </div>
        </div>
        <div v-else class="center_top_div">
          <span class="span" @click="router.push('/login')">立即登录</span>
          <svg class="icon icon_span" aria-hidden="true" @click="router.back()">
            <use xlink:href="#icon-xiangyoujiantou"></use>
          </svg>
        </div>
      </div>
      <div class="center_center">
        <base-grid :grid="grid"></base-grid>
      </div>
      <div class="center_footer">
        <div class="footer_like">
          <img :src="token ? profile.avatarUrl : ''" alt="" class="like_left" />
          <div class="like_center" @click="router.push('/userList')">
            <p class="likeP">我喜欢的音乐</p>
            <span class="likeSpan">{{ token ? likeSong.length : 0 }}首</span>
          </div>
          <div class="like_right">
            <van-button round type="default" size="small">
              <svg class="icon icon_like_right" aria-hidden="true" @click="router.back()">
                <use xlink:href="#icon-aixin"></use>
              </svg>
              <span class="span_like_right">心动模式</span></van-button
            >
          </div>
        </div>
      </div>
    </div>
    <div class="user_bottom">
      <van-tabs
        class="bottom_text"
        v-model:active="active"
        scrollspy
        sticky
        line-width="1.2rem"
        line-height="0.1rem"
      >
        <van-tab title="创建歌单" class="bottomList">
          <div class="bottom_item">
            <img src="" alt="" class="item_left" />
            <div class="item_center">
              <p class="itemP">我喜欢的音乐</p>
              <span class="itemSpan">431首</span>
            </div>
            <div class="item_right"></div>
          </div>
        </van-tab>
        <van-tab title="收藏歌单" class="bottomList">
          <div class="bottom_item">
            <img src="" alt="" class="item_left" />
            <div class="item_center">
              <p class="itemP">我喜欢的音乐</p>
              <span class="itemSpan">431首</span>
            </div>
            <div class="item_right"></div>
          </div>
        </van-tab>
        <van-tab title="歌单助手" class="bottomList">
          <div class="bottom_item">
            <img src="" alt="" class="item_left" />
            <div class="item_center">
              <p class="itemP">我喜欢的音乐</p>
              <span class="itemSpan">431首</span>
            </div>
            <div class="item_right"></div>
          </div>
        </van-tab>
      </van-tabs>
    </div>
    <van-button round block type="default" native-type="submit" class="logout" @click="logout">
      <svg class="icon logout_icon_right" aria-hidden="true">
        <use xlink:href="#icon-tuichudenglu"></use>
      </svg>
      <span class="logout_right">退出登录</span>
    </van-button>
  </div>
</template>

<script lang="ts" setup>
import { computed, ref } from 'vue'
import { useRouter } from 'vue-router'
import BaseGrid from '@/base_ui/Grid/base_grid.vue'
import { useStore } from '@/store'
import cache from '@/utils/cache/cache'
//grid的配置文件
import { grid } from './config/infoLogin'

//通过 v-model:active 绑定当前激活标签对应的索引值，默认情况下启用第一个标签
const active = ref(0)
const isShow = ref(true)
const store = useStore()
const router = useRouter()
//用token控制v-if
const token = computed(() => store.state.login.token)

//拿到头像等级等等
const profile = computed(() => store.state.login.profile)
const userInfo = computed(() => store.state.login.userInfo)
//拿到喜欢的所有音乐信息
const likeSong = computed(() => store.state.login.likeSongInfo)
//退出登录
const logout = () => {
  cache.deleteCache('token')
  store.dispatch('login/logout')
  router.go(0)
}
</script>

<style scoped lang="less">
.user {
  width: 100%;
  height: 100%;
  background-color: rgb(240, 240, 240);
  overflow: scroll;
  .user_top {
    height: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.2rem;
  }
  .user_center {
    width: 100%;
    display: flex;
    align-items: center;
    flex-direction: column;
    .center_top {
      display: flex;
      flex-direction: column;
      width: 100%;
      height: 2.3rem;
      position: relative;
      padding: 0.2rem;
      padding-top: 0;
      .img_div {
        flex: 1;
        max-height: 0.5rem;
        .center_top_img {
          width: 1rem;
          height: 1rem;
          border-radius: 50%;
          overflow: hidden;
          position: absolute;
          left: 50%;
          transform: translateX(-50%);
        }
      }
      .center_top_div_login {
        flex: 2;
        background-color: #fff;
        display: flex;
        flex-direction: column;
        text-align: center;
        justify-content: flex-end;
        border-radius: 0.2rem;
        padding-bottom: 0.1rem;
        .center_top_div_info {
          span {
            margin: 0 0.1rem;
          }
        }
        .span {
          font-weight: 900;
        }
        .icon_span {
          width: 0.35rem;
          height: 0.35rem;
          margin-left: 0.1rem;
          vertical-align: middle;
        }
      }
      .center_top_div {
        flex: 2;
        background-color: #fff;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 0.2rem;

        .span {
          font-weight: 900;
        }
        .icon_span {
          width: 0.35rem;
          height: 0.35rem;
          margin-left: 0.1rem;
        }
      }
    }
    .center_center {
      border-radius: 0.2rem;
      overflow: hidden;
      padding: 0.2rem;
      padding-top: 0;
      width: 100%;
    }
    .center_footer {
      width: 100%;
      .footer_like {
        height: 1.4rem;
        display: flex;
        align-items: center;
        background-color: #fff;
        margin: 0.2rem;
        margin-top: 0;
        overflow: hidden;
        border-radius: 0.2rem;
        padding-left: 0.2rem;
        .like_left {
          flex: 2.5;
          width: 75%;
          display: flex;
          justify-content: center;
          height: 75%;
          border-radius: 50%;
          overflow: hidden;
        }
        .like_center {
          flex: 4;
          display: flex;
          flex-direction: column;
          justify-items: center;

          padding-left: 0.2rem;
          .likeP {
            width: 4rem;
            font-weight: 900;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
          .likeSpan {
            font-weight: normal;
            color: rgb(135, 134, 134);
          }
        }
        .like_right {
          flex: 4;
          display: flex;
          align-items: center;

          .span_like_right {
            vertical-align: middle;
          }
          .icon_like_right {
            vertical-align: middle;
            width: 0.25rem;
            height: 0.25rem;
          }
        }
      }
    }
  }
  .user_bottom {
    border-radius: 0.2rem;
    background-color: #fff;
    margin: 0.2rem;
    padding: 0.2rem;
    margin-top: 0;
    padding-top: 0;
    .bottom_text {
      width: 100%;
      height: 100%;

      .bottomList {
        width: 100%;
        height: 100%;
        .bottom_item {
          height: 1.4rem;
          display: flex;
          align-items: center;
          background-color: #fff;
          margin: 0.2rem;
          margin-top: 0;
          overflow: hidden;
          border-radius: 0.2rem;
          .item_left {
            flex: 2;
            display: flex;
            justify-content: center;
            height: 100%;
            border-radius: 50%;
            overflow: hidden;
          }
          .item_center {
            flex: 4;
            display: flex;
            flex-direction: column;
            justify-items: center;

            padding-left: 0.2rem;
            .itemP {
              width: 4rem;
              font-weight: 900;
              overflow: hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
            }
            .itemSpan {
              font-weight: normal;
              color: rgb(135, 134, 134);
            }
          }
          .item_right {
            flex: 4;
            display: flex;
            align-items: center;

            .span_like_right {
              vertical-align: middle;
            }
            .icon_like_right {
              vertical-align: middle;
              width: 0.25rem;
              height: 0.25rem;
            }
          }
        }
      }
    }
  }
  .logout {
    width: 50%;
    height: 1rem;
    margin: 0.2rem auto;
    text-align: center;
    .logout_icon_right {
      vertical-align: middle;
    }
    .logout_right {
      vertical-align: middle;
      color: rgb(222, 6, 6);
    }
  }
}
</style>
